//
//  ViewController.m
//  ibeacon
//
//  Created by MyMac on 15/9/10.
//  Copyright (c) 2015年 tongfang. All rights reserved.
//

#import "ViewController.h"
#import <CoreBluetooth/CoreBluetooth.h>
#import <CoreLocation/CoreLocation.h>
NSString *const UUIDString=@"76B5F6C3-6390-4BBC-B3C9-84AD8C92BCA5";
//服务端要发送消息，，所以要实现周边协议
@interface ViewController ()<CBPeripheralManagerDelegate>
@property(nonatomic,strong)CLBeaconRegion*myBeaconRegion;
@property(nonatomic,strong)NSMutableDictionary*myBeaconData;
@property(nonatomic,strong)CBPeripheralManager*peripheraMsg;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSUUID *UUID=[[NSUUID alloc]initWithUUIDString:UUIDString];
    CLBeaconMajorValue major=111;
    CLBeaconMinorValue minor=50;
    self.myBeaconRegion=[[CLBeaconRegion alloc]initWithProximityUUID:UUID major:major minor:minor identifier:[[NSBundle mainBundle]bundleIdentifier]];
    //用于发送广播时的数据
    //CLBeaconRegion相当于一个标志，通过寻找这个标志来搜索他的信息
    //此方法就是存储了CLBeaconRegion的信息，类似于周边的服务一样
  self.myBeaconData=[self.myBeaconRegion peripheralDataWithMeasuredPower:nil];//传参，传一个RSSI值，这里传nil，，，系统会有一个默认值
    self.peripheraMsg=[[CBPeripheralManager alloc]initWithDelegate:self queue:nil options:nil];
    
}
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral
{
    if(peripheral.state==CBPeripheralManagerStatePoweredOn){
        NSLog(@"开始广播");
        [self.peripheraMsg startAdvertising:self.myBeaconData];
    
    }else if (peripheral.state==CBPeripheralManagerStatePoweredOff){
        NSLog(@"停止广播");
        [self.peripheraMsg stopAdvertising];
    
    
    }




}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
